package com.smart.tool.pipeline;

import java.util.Map;

/**
 * @Author gao.gwq
 * @Version Handler.java, v 0.1 2024年05月27日 11:33 gao.gwq
 * @Description: TODO
 */
public interface Handler<I, O> {

    default void beforeProcess(I input){

    }

    default O doProcess( I input){

        O output = null;
        Throwable error = null;
        try {
            beforeProcess(input);
            output = process(input);
            afterProcess(input,output);
            return output;
        }catch (Throwable throwable){
            error = throwable;
            throw  throwable;
        }finally {
            completeProcess(input,output,error);
        }
    }

     O process(I input);

    default void afterProcess(I input,O output){

    }

    default void completeProcess(I input,O output,Throwable error){

    }

}